#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=3e5+10;
struct ComparePair {
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2) {
        if (p1.first == p2.first) {
            return p1.second > p2.second;
        } else {
            return p1.first < p2.first;
        }
    }
};
int a[N];
int main()
{
	IOS;
	int t;
	cin>>t;
	while(t--)
	{
		priority_queue<pair<int, int>, vector<pair<int, int>>, ComparePair> q;
		ll n,k;
		cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			int num;
			cin>>num;
			q.push({num,i});
		}
		int cnt=0; 
		while(q.size())
		{
			ll x=q.top().first;
			ll y=q.top().second;
//			cout<<x<<' '<<y<<endl;
			q.pop();
			if(x<=k)
			{
				cnt++;
				a[cnt]=y;
			}
			else
			{
				if(x%k==0)
				{
					x=k;
				}
				else x=x-x/k*k;
				q.push({x,y});
			}
		}
		for(int i=1;i<=n;i++)
		{
			cout<<a[i]<<' ';
			a[i]=0;
		}
		cout<<endl;
	}

	return 0;
}

